<template>
	<view class="bg">
		<view class="main">
			<view class="logo-name-container">
				<image class="logo" src="/static/login/logo.png"></image>
				<view class="name-zh">
					上海展天地理云教学互动系统
				</view>
				<view class="name-en">
					Shanghai Zhantian Geography cloud teaching interactive system
				</view>
			</view>
			<view class="split"></view>
			<view class="loginContainer">
				<input type="text" placeholder="学校" v-model="schoolName" />
				<input type="text" placeholder="班级" v-model="className" />
				<input type="text" placeholder="姓名" v-model="studentName" />
				<input type="text" placeholder="学号" v-model="studentNo" />
				<input password type="text" placeholder="密码" v-model="password" />
				<view class="button" @click="login">登录</view>
			</view>
		</view>

		<view class="version">
			<!-- #ifdef APP-PLUS -->
			{{$store.state.version.wgt_version}}
			<!-- #endif -->
			
			<!-- #ifdef H5 -->
			{{wgt_version}}
			<!-- #endif -->
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				schoolName: "",
				studentNo: "",
				className: "",
				studentName: "",
				password: "",
				// #ifdef H5
				wgt_version: uni.getSystemInfoSync().appVersion,
				// #endif
			}
		},
		methods: {
			login() {
				let queryInput = {
					schoolName: this.schoolName,
					studentNo: this.studentNo,
					className: this.className,
					studentName: this.studentName,
					password: this.password,
				}

				if (process.env.NODE_ENV == "development") {
					//测试环境允许直接登录
					
					queryInput = {
						studentNo: "001",
						schoolName: "浦东中学",
						className: "测试班级",
						studentName: "",
						password: "123qwe",
					}
				}

				this.axios
					.post("/api/TokenAuth/StudentAuthenticate", queryInput)
					.then((data) => {
						console.log("data", data)
						this.$store.setSession("token", "Bearer " + data.accessToken)
						uni.setStorageSync("token", "Bearer " + data.accessToken)

						this.axios.get("/api/services/app/Task/GetPersonInfo").then(res => {
							this.$store.setSession("schoolId", res.schoolId)
							this.$store.setSession("schoolName", res.schoolName)
							this.$store.setSession("studentNo", res.studentNo)
							this.$store.setSession("classId", res.classId)
							this.$store.setSession("className", res.className)
							this.$store.setSession("userId", res.userId)
							this.$store.setSession("userName", res.userName)

							uni.reLaunch({
								url: "/pages/index/index"
							})

						})

					});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg {
		width: 100vw;
		height: 100vh;
		background-image: url('~@/static/login/bg.png');
		background-size: cover;
		background-position: center;
	}

	.main {
		height: 40vh;
		width: 65vw;
		display: flex;
		position: absolute;
		left: 50vw;
		top: 50vh;
		transform: translate(-50%, -50%);
	}

	.logo-name-container {
		width: 50%;
		color: #fff;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.logo {
			width: 5.2vw;
			height: 4.5vw;
		}

		.name-zh {
			font-size: 1.8vw;
			letter-spacing: 0.2vw;
			margin-top: 1.5vw;
			height: 2vw;
			line-height: 2vw;
		}

		//通过缩放方式，解决font-size无法小于12px的问题
		.name-en {
			// font-size: 0.8vw;
			// margin-top: 0.5vw;
			// height: 1vw;
			// line-height: 1vw;
			font-size: 1.8vw;
			height: 2vw;
			line-height: 2vw;
			transform: scale(0.5);
			white-space: nowrap;
		}
	}

	.split {
		background-color: #3D70A7;
		width: 0.2vw;
		height: 100%;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}

	.loginContainer {
		width: 50%;
		box-sizing: border-box;
		padding: 0 5vw;
		display: flex;
		flex-direction: column;
		justify-content: center;

		input {
			font-size: 1.2vw;
			color: #fff;
			border-bottom: 0.2vw solid #fff;
			padding: 0.5vw 0.2vw;
			margin-top: 0.5vw;

			.input-placeholder {
				color: rgba(255, 255, 255, 0.5);
			}
		}

		.button {
			color: #fff;
			background-color: #247FE8;
			border-radius: 0.3vw;
			text-align: center;
			height: 2.8vw;
			line-height: 2.8vw;
			font-size: 1.2vw;
			letter-spacing: 0.1vw;
			margin-top: 2vw;
		}
	}

	.version {
		position: absolute;
		right: 5px;
		bottom: 5px;
		color: #fff;
		opacity: 0.3;
		font-size: 12px;
		transform: scale(0.6);
	}
</style>